package com.example.cookieandsession.session;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: StuController
 * Package: com.example.cookieandsession.session
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-04-12
 * Time: 22:21
 */
@RestController
@RequestMapping("/stu")
public class StuController {

    @PostMapping("/list")
    public void session(HttpServletRequest request, HttpServletResponse response) throws IOException {

        //获取前端传来的参数
        String username = request.getParameter("username");

        //将参数放入request域
        request.setAttribute("user",username);

        //放到Session中 ture
        request.getSession().setAttribute("USERNAME",username);

        //响应回数据
        response.getWriter().println("request: " + username);

        /**
         * 对于request的getSession()
         * 一般请求 若向Session中写入数据 参数为ture
         * 使用则是 false 读取数据 有就读取 没有就返回null
         */

    }

}
